package double_pointer;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-12-01
 * Time: 9:22
 */
public class TriangleNumber {
    public static int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int count = 0;
        for(int i = nums.length - 1; i > 1; i--) {
            int left = 0;
            int right = i - 1;
            while(right > left) {
                if(nums[left] + nums[right] > nums[i]) {
                    count += right - left;
                    right--;
                } else {
                    left++;
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(triangleNumber(new int[]{4, 2, 3, 4}));
    }
}
